// DrawPenCtrler.cpp: implementation of the CDrawPenCtrler class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../Resource.h"
#include "DrawPenCtrler.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CDrawPenCtrler::CDrawPenCtrler(COLORREF color, int width, long style)
: m_x(0), m_y(0)
{
	SetColor (color);		// set the pen color
	SetPenWidth (width);	// set the pen width
	SetPenStyle (style);	// set the pen style

	m_TaskTyle = ID_PEN;	// a pen that can draw any shape.
}

CDrawPenCtrler::~CDrawPenCtrler()
{
}

void CDrawPenCtrler::StartPoint(long x, long y)
{
	m_DrawRect.right = m_DrawRect.left = m_x = x;
	m_DrawRect.bottom = m_DrawRect.top = m_y = y;
}

void CDrawPenCtrler::MoveAt(CDC *pDC, long x, long y)
{
	//
	// Set the CPen //////////////////////////////////////////
	//
	CPen pen(GetPenStyle(), GetPenWidth(), GetColor());
	CPen* oldpen = pDC->SelectObject(&pen);

	// recorde the Draw Rectangle
	m_DrawRect.left = min(m_DrawRect.left, x - GetPenWidth());
	m_DrawRect.right = max(m_DrawRect.right, x + GetPenWidth());
	m_DrawRect.top = min(m_DrawRect.top, y - GetPenWidth());
	m_DrawRect.bottom = max(m_DrawRect.bottom, y + GetPenWidth());

	pDC->MoveTo(m_x, m_y);
	m_x = x;
	m_y = y;
	pDC->LineTo(x, y);

	// recover the DC :
	pDC->SelectObject(oldpen);
	pen.DeleteObject();
}